import http from '@/utils/request'

/**
 * 获取动态参数或者静态属性
 * @param {Number} id
 * @param {String} type 取值为only,many
 * @returns
 */
export const getParamsApi = (id, type) => {
    return http(`/categories/${id}/attributes`, 'get', {
        sel: type
    })
}

/**
 * 实现属性名称的更新或者属性值的更新（属性值的增加、删除、修改）操作
 * @param {Number} catId 分类id
 * @param {Number} attrId 属性id
 * @param {String}  attrVals  属性值，多个属性值使用,隔开，如果是做属性值的操作，必填，属性名称更新不需要
 * @param {String} attrName 属性名称，必填
 * @param {String} attrSel 属性类型,only和many 必填
 * @returns
 */

export const updateParamsApi = ({
    catId,
    attrId,
    attrVals = '',
    attrName,
    attrSel
}) => {
    return http(`/categories/${catId}/attributes/${attrId}`, 'put', {
        attr_vals: attrVals,
        attr_name: attrName,
        attr_sel: attrSel
    })
}

/**
 * 添加属性
 * @param {Number} catId 分类id
 * @param {String} attrName 属性名称
 * @param {String} attrSel 类型：only和many
 * @returns
 */

export const addParamsApi = ({
    catId,
    attrName,
    attrSel
}) => {
    return http(`/categories/${catId}/attributes`, 'post', {
        attr_name: attrName,
        attr_sel: attrSel
    })
}

/**
 * 删除属性
 * @param {Number} catId 分类id
 * @param {Number} attrId 属性id
 * @returns
 */

export const delAttrApi = ({
    catId,
    attrId
}) => {
    return http(`/categories/${catId}/attributes/${attrId}`, 'delete')
}